<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Jump Labels</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.12.4.min.js"
	integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>

<script src="../docs-assets/Bigfoot.js"></script>
<link href="../docs-assets/Bigfoot.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Jump Labels' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">imperative</a></li><li><a href="index.html#3">Chapter 3: Functions</a></li><li><b>Jump Labels</b></li></ul></div>
<p class="purpose">Generating numbered families of identifier names to use as jump labels, and creating any associated array storage needed.</p>

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>At the risk of angering the ghost of Dijkstra, we compile plenty of <span class="extract"><span class="extract-syntax">JUMP_BIP</span></span>
opcodes in the Inter functions we make, and these require labels to jump to.
Clearly we could just call these <span class="extract"><span class="extract-syntax">L0</span></span>, <span class="extract"><span class="extract-syntax">L1</span></span>, <span class="extract"><span class="extract-syntax">L2</span></span>, ..., <span class="extract"><span class="extract-syntax">L3475</span></span>, ..., but that
would make the Inter code we're generating harder for human eyes to read. So we
will go to a little trouble to give meaningful names.
</p>

<p class="commentary">In particular, labels are generated within "namespaces", which are really just
numbered sets, except that they can also have associated storage,<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> which is
global and persistent:
</p>

<ul class="footnotetexts"><li class="footnote" id="fn:1"><p class="inwebfootnote"><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> Labels and storage are not obviously related, but in fact these small pieces
of storage are used in "say" phrases to choose alternative wordings, where the
options correspond to labels to jump to.
<a href="#fnref:1" title="return to text"> &#x21A9;</a></p></li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">label_prefix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">label_counter</span><span class="plain-syntax">; </span><span class="comment-syntax"> next free ID number for this label namespace</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">max_label_counter</span><span class="plain-syntax">; </span><span class="comment-syntax"> largest ever value of the label counter</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">allocate_storage</span><span class="plain-syntax">; </span><span class="comment-syntax"> number of words of memory to reserve for each label</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">label_storage_iname</span><span class="plain-syntax">; </span><span class="comment-syntax"> where that storage is</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">storage_requested</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">storage_compiled</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure label_namespace is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>This function writes the current label identifier within the given namespace.
This takes the form <span class="extract"><span class="extract-syntax">L_NameNumber</span></span>. For instance, <span class="extract"><span class="extract-syntax">L_Marble17</span></span> is the 18th label
in namespace <span class="extract"><span class="extract-syntax">Marble</span></span>.
</p>

<p class="commentary">It is legal for a namespace's name to be the empty text, which generates labels
<span class="extract"><span class="extract-syntax">L_0</span></span>, <span class="extract"><span class="extract-syntax">L_1</span></span>, ...
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JumpLabels::write</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::write</span></span>:<br/>Compile Blocks and Lines - <a href="5-cbal.html#SP4_5_3">&#167;4.5.3</a><br/>Compile Invocations Inline - <a href="5-cii.html#SP6_4_1">&#167;6.4.1</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax"> = </span><a href="3-jl.html#SP3" class="function-link"><span class="function-syntax">JumpLabels::obtain_namespace</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"L_%S%d"</span><span class="plain-syntax">, </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_prefix</span><span class="plain-syntax">, </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>The rest of Inform tends not to store pointers to namespaces: instead it
must indicate them by their textual prefixes. This is very slightly inefficient,
but there are very few namespaces in any single function.
</p>

<p class="commentary">However, the namespace <span class="extract"><span class="extract-syntax">Whatever</span></span> is different for different functions &mdash; jump
labels, after all, are private to functions. <span class="extract"><span class="extract-syntax">JumpLabels::obtain_namespace(I"Whatever")</span></span>
will return the namespace for whatever we are currently compiling.
</p>

<p class="commentary">This leads to an interesting nuance, which is that functions which are instantiations
of templates will share a common list. (See <a href="3-fnc.html#SP4" class="internal">Functions::current_label_namespaces</a>.)
That means that they share their storage, if they have any. For example, label
storage is used to manage the alternate texts in the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">To</span><span class="plain-syntax"> </span><span class="identifier-syntax">judge</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax"> - </span><span class="identifier-syntax">value</span><span class="plain-syntax">):</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="string-syntax">"[V] is [one of]clearly[or]evidently[or]markedly[cycling] just plain [V]."</span>
<span class="identifier-syntax">When</span><span class="plain-syntax"> </span><span class="identifier-syntax">play</span><span class="plain-syntax"> </span><span class="identifier-syntax">begins</span><span class="plain-syntax">:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">judge</span><span class="plain-syntax"> </span><span class="constant-syntax">21</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">judge</span><span class="plain-syntax"> </span><span class="string-syntax">"fishslice"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">judge</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">time</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">day</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">judge</span><span class="plain-syntax"> </span><span class="identifier-syntax">true</span><span class="plain-syntax">.</span>
</pre>
<p class="commentary">Here "to judge" is instantiated four times (for when <span class="extract"><span class="extract-syntax">V</span></span> is a number, when it
is a text, when it is a time of day, and when it is a truth state). The output
here should be:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">21</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">21</span><span class="plain-syntax">.</span>
<span class="identifier-syntax">fishslice</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">evidently</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="identifier-syntax">fishslice</span><span class="plain-syntax">.</span>
<span class="constant-syntax">9</span><span class="plain-syntax">:00 </span><span class="identifier-syntax">am</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">markedly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">9</span><span class="plain-syntax">:00 </span><span class="identifier-syntax">am</span><span class="plain-syntax">.</span>
<span class="identifier-syntax">true</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="identifier-syntax">true</span><span class="plain-syntax">.</span>
<span class="constant-syntax">56</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">evidently</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">56</span><span class="plain-syntax">.</span>
</pre>
<p class="commentary">In other words, the counter used in all four instance functions must be the
same one; if they had all had independent counters, the result would be:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="constant-syntax">21</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">21</span><span class="plain-syntax">.</span>
<span class="identifier-syntax">fishslice</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="identifier-syntax">fishslice</span><span class="plain-syntax">.</span>
<span class="constant-syntax">9</span><span class="plain-syntax">:00 </span><span class="identifier-syntax">am</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">9</span><span class="plain-syntax">:00 </span><span class="identifier-syntax">am</span><span class="plain-syntax">.</span>
<span class="identifier-syntax">true</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">clearly</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="identifier-syntax">true</span><span class="plain-syntax">.</span>
<span class="constant-syntax">56</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">evidently</span><span class="plain-syntax"> </span><span class="identifier-syntax">just</span><span class="plain-syntax"> </span><span class="identifier-syntax">plain</span><span class="plain-syntax"> </span><span class="constant-syntax">56</span><span class="plain-syntax">.</span>
</pre>
<p class="commentary">See the test case <span class="extract"><span class="extract-syntax">InstantiatedLabelStorage</span></span>.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">MAX_NAMESPACE_PREFIX_LENGTH</span><span class="plain-syntax"> </span><span class="constant-syntax">20</span><span class="plain-syntax"> </span><span class="comment-syntax"> when </span><span class="extract"><span class="extract-syntax">L_</span></span><span class="comment-syntax"> and a number are added, we are within 31 chars</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="function-syntax">JumpLabels::obtain_namespace</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::obtain_namespace</span></span>:<br/><a href="3-jl.html#SP2">&#167;2</a>, <a href="3-jl.html#SP5">&#167;5</a>, <a href="3-jl.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linked_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespaces</span><span class="plain-syntax"> = </span><a href="3-fnc.html#SP4" class="function-link"><span class="function-syntax">Functions::current_label_namespaces</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">namespaces</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"labels are available only within functions"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">, </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">, </span><span class="identifier-syntax">namespaces</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_prefix</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">lns</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">MAX_NAMESPACE_PREFIX_LENGTH</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_LabelNamespaceTooLong</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a label namespace prefix is too long"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"and should be shortened to a few alphabetic characters."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Str::truncate</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="constant-syntax">MAX_NAMESPACE_PREFIX_LENGTH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_prefix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_storage_iname</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Enclosures::new_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">LABEL_STORAGES_HAP</span><span class="plain-syntax">, </span><span class="identifier-syntax">LABEL_ASSOCIATED_STORAGE_HL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">max_label_counter</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allocate_storage</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_compiled</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_requested</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ADD_TO_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">, </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">, </span><span class="identifier-syntax">namespaces</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">lns</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>Though multiple instantiations of the same imperative definition may share
a namespace list, we need to reset all the counters each time it is instantiated:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JumpLabels::restart_counters</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::restart_counters</span></span>:<br/>Functions - <a href="3-fnc.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">id_body</span><span class="plain-syntax"> *</span><span class="identifier-syntax">idb</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">, </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">, </span><span class="identifier-syntax">idb</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">compilation_data</span><span class="plain-syntax">.</span><span class="element-syntax">label_namespaces</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>An individual counter can be read, advanced or retreated with:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">JumpLabels::read_counter</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::read_counter</span></span>:<br/>Compile Blocks and Lines - <a href="5-cbal.html#SP4_5_3">&#167;4.5.3</a><br/>Compile Invocations Inline - <a href="5-cii.html#SP6_4_2">&#167;6.4.2</a>, <a href="5-cii.html#SP6_4_4">&#167;6.4.4</a>, <a href="5-cii.html#SP6_4_5">&#167;6.4.5</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">advance_by</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax"> = </span><a href="3-jl.html#SP3" class="function-link"><span class="function-syntax">JumpLabels::obtain_namespace</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax"> += </span><span class="identifier-syntax">advance_by</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">max_label_counter</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">max_label_counter</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_counter</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"label counter negative"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>So, then, we can mark a namespace as requiring 1 or more words of storage.
This will accumulate into an array, as follows.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JumpLabels::allocate_storage</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::allocate_storage</span></span>:<br/>Compile Invocations Inline - <a href="5-cii.html#SP6_4_6">&#167;6.4.6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">multiplier</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax"> = </span><a href="3-jl.html#SP3" class="function-link"><span class="function-syntax">JumpLabels::obtain_namespace</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">multiplier</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allocate_storage</span><span class="plain-syntax">) </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allocate_storage</span><span class="plain-syntax"> = </span><span class="identifier-syntax">multiplier</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_requested</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">JumpLabels::storage_iname</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::storage_iname</span></span>:<br/>Compile Invocations Inline - <a href="5-cii.html#SP6_4_3">&#167;6.4.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax"> = </span><a href="3-jl.html#SP3" class="function-link"><span class="function-syntax">JumpLabels::obtain_namespace</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">namespace</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_storage_iname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>When a function body is completed, this is then called to create the necessary
storage space, if any:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JumpLabels::compile_necessary_storage</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">JumpLabels::compile_necessary_storage</span></span>:<br/>Functions - <a href="3-fnc.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linked_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">namespaces</span><span class="plain-syntax"> = </span><a href="3-fnc.html#SP4" class="function-link"><span class="function-syntax">Functions::current_label_namespaces</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lns</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">, </span><span class="reserved-syntax">label_namespace</span><span class="plain-syntax">, </span><span class="identifier-syntax">namespaces</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_compiled</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_requested</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">allocate_storage</span><span class="plain-syntax">)*(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">max_label_counter</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">N</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="identifier-syntax">save</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitArrays::begin_word</span><span class="plain-syntax">(</span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">label_storage_iname</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">N</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">EmitArrays::numeric_entry</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">N</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">EmitArrays::numeric_entry</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitArrays::end</span><span class="plain-syntax">(</span><span class="identifier-syntax">save</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">lns</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">storage_compiled</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="3-fnc.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-im.html">1</a></li><li class="progresschapter"><a href="2-cv.html">2</a></li><li class="progresscurrentchapter">3</li><li class="progresssection"><a href="3-sf.html">sf</a></li><li class="progresssection"><a href="3-lvs.html">lvs</a></li><li class="progresssection"><a href="3-lv.html">lv</a></li><li class="progresssection"><a href="3-tv.html">tv</a></li><li class="progresssection"><a href="3-lp.html">lp</a></li><li class="progresssection"><a href="3-cb.html">cb</a></li><li class="progresssection"><a href="3-fnc.html">fnc</a></li><li class="progresscurrent">jl</li><li class="progresssection"><a href="3-pr.html">pr</a></li><li class="progresssection"><a href="3-cls.html">cls</a></li><li class="progresssection"><a href="3-cid.html">cid</a></li><li class="progresschapter"><a href="4-cs.html">4</a></li><li class="progresschapter"><a href="5-cbal.html">5</a></li><li class="progressnext"><a href="3-pr.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

